package com.isoft.c2team3service2.service.impl;

import com.isoft.c2team3service2.service.MountingService;
import com.isoft.c2team3service2.util.RedisConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.isoft.c2team3service2.util.RedisConstants.ARTIST_RECENT_ACCESS_TIME;

@Service
public class MountingServiceImpl implements MountingService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public long mounting(String name) {
        LocalDateTime nowDt = LocalDateTime.now() ;

        String o =(String) stringRedisTemplate.opsForHash().get(ARTIST_RECENT_ACCESS_TIME,name);

        System.out.println("_____________" + o);

        if (o != null) {
            LocalDateTime birthInfo = LocalDateTime.parse(o);
            Duration duration = Duration.between(birthInfo, nowDt);

            long l = duration.getSeconds() / 60;

            return l;
        }else{
            return 0L;
        }
    }
}